package cn.sgrand.ioc.service.impl;

import cn.sgrand.ioc.dao.SysuserMapper;
import cn.sgrand.ioc.service.SysuserService;
import cn.sgrand.pojo.Sysuser;
import cn.sgrand.pojo.SysuserExample;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * Created by ggj on 2016/12/6.
 */

@Service
public class SysuserServiceImpl implements SysuserService {

    @Resource
    private SysuserMapper sysuserDao;

    @Override
    public Sysuser findSysuserByUsername(String username) {
        SysuserExample sysuserExample = new SysuserExample();
        SysuserExample.Criteria criteria = sysuserExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Sysuser> sysusers = sysuserDao.selectByExample(sysuserExample);
        if (!sysusers.isEmpty() || sysusers.size() > 0)
            return sysusers.get(0);
        return null;
    }

    @Override
    public boolean authSysuser(Sysuser sysuser) {
        String username = sysuser.getUsername();
        String password = sysuser.getPassword();
        Sysuser sysuserByUsername = findSysuserByUsername(username);
        if (sysuserByUsername == null)
            return false;
            if (username.equals(sysuserByUsername.getUsername()) && password.equals(sysuserByUsername.getPassword()))
                return true;
            return false;
    }
}